package com.example.personalaccount.service.impl;


import com.example.personalaccount.entity.User;
import com.example.personalaccount.repository.UserRepository;
import com.example.personalaccount.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

@Service("userService")

public class UserServiceImpl implements UserService {
    @Autowired
   private UserRepository userRepository ;

    @Override
    public User getUserById(long userId) {
        User user = userRepository.getUserById(userId);
        if (user == null) { throw  new IllegalArgumentException("User not found") ;}
        return user;
    }

    @Override
    public User getUserByUsername(String username) {
        User user = userRepository.getUserByUsername(username);
        return user;
    }

    @Override
    public User update(User user) {
        User user1 = userRepository.getUserById(user.getId());
        user1.setStatus(user.getStatus());
        user1.setTelephone(user.getTelephone());
        return userRepository.save(user1);
    }


}
